//
//  ZYSecondViewController.m
//  XiangMuYiBai
//
//  Created by mac on 15-4-19.
//  Copyright (c) 2015年 zhiyou. All rights reserved.
//

#import "ZYSecondViewController.h"
#import "Header.h"
@interface ZYSecondViewController ()

@end

@implementation ZYSecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];//圆中心 160 274  半径100
    UIImageView *beiJing = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 320, 480)];
    beiJing.image = [UIImage imageNamed:@"bg2.jpg"];
    [self.view addSubview:beiJing];
  
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem];
    btn.center=CGPointMake(160, 274);
    btn.bounds=CGRectMake(0, 0, 30, 30);
    [btn setTitle:@"0" forState:UIControlStateNormal];
    [self.view addSubview:btn];
    btn1=[UIButton buttonWithType:UIButtonTypeSystem];
    btn1.center=CGPointMake(160, 174);
    btn1.bounds=CGRectMake(0, 0, 65, 65);
   // [btn1 setTitle:@"0" forState:UIControlStateNormal];
    [btn1 setBackgroundImage:[UIImage imageNamed:@"m_item4.png"] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    btn1.tag=1;
    [self.view addSubview:btn1];
    btn2=[UIButton buttonWithType:UIButtonTypeSystem];
    btn2.center=CGPointMake(260, 274);
    btn2.bounds=CGRectMake(0, 0, 65, 65);
    [btn2 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
   // [btn2 setTitle:@"0" forState:UIControlStateNormal];
    [btn2 setBackgroundImage:[UIImage imageNamed:@"m_item1.png"] forState:UIControlStateNormal];
    btn2.tag=2;
    [self.view addSubview:btn2];

    btn3=[UIButton buttonWithType:UIButtonTypeSystem];
    btn3.center=CGPointMake(160, 374);
    btn3.bounds=CGRectMake(0, 0, 65, 65);
   // [btn3 setTitle:@"0" forState:UIControlStateNormal];
    [btn3 setBackgroundImage:[UIImage imageNamed:@"m_item2.png"] forState:UIControlStateNormal];
    btn3.tag=3;
    [btn3 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn3];

    btn4=[UIButton buttonWithType:UIButtonTypeSystem];
    btn4.center=CGPointMake(60, 274);
    btn4.bounds=CGRectMake(0, 0, 65, 65);
    //[btn4 setTitle:@"0" forState:UIControlStateNormal];
    [btn4 setBackgroundImage:[UIImage imageNamed:@"m_item3.png"] forState:UIControlStateNormal];
    btn4.tag=4;
    [btn4 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn4];
    i2=90;
    i3=180;
    i4=270;
}
-(void)click:(UIButton*)btn
{
    NSLog(@"111");
    a=btn.tag;
    if (btn.tag != 1)
    {
        time= [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(time1) userInfo:nil repeats:YES];
    }
    else
    {
        [self star];
        
    }

}
-(void)time1
{
    i1=i1+1;
    i2=i2+1;
    i3=i3+1;
    i4=i4+1;
    float y1=274- 100 * cos(i1 *M_PI /180);
    float x1=160+ 100 * sin(i1 *M_PI/180);
    btn1.center=CGPointMake(x1, y1);
    float y2=274- 100 * cos(i2 *M_PI /180);
    float x2=160+ 100 * sin(i2 *M_PI/180);
    btn2.center=CGPointMake(x2, y2);
    float y3=274- 100 * cos(i3 *M_PI /180);
    float x3=160+ 100 * sin(i3 *M_PI/180);
    btn3.center=CGPointMake(x3, y3);
    float y4=274- 100 * cos(i4 *M_PI /180);
    float x4=160+ 100 * sin(i4 *M_PI/180);
    btn4.center=CGPointMake(x4, y4);

    if (i1==90 || i1==180 || i1==270 || i1==360)
    {
        
        btn1.tag=btn1.tag+1;
        btn2.tag=btn2.tag+1;
        btn3.tag=btn3.tag+1;
        btn4.tag=btn4.tag+1;
        NSLog(@" 1bt1 %d",btn1.tag);
        NSLog(@"1bt2  %d",btn2.tag);
        NSLog(@" 1bt3 %d",btn3.tag);
        NSLog(@" 1bt4  %d",btn4.tag);
        if (btn1.tag==5)
        {
            btn1.tag=1;
        }
       else if (btn2.tag==5)
        {
            btn2.tag=1;
        }
       else if (btn3.tag==5)
        {
            btn3.tag=1;
        }
       else if (btn4.tag==5)
        {
            btn4.tag=1;
        }
        a=a+1;
        if (a==5)
        {
            [self performSelector:@selector(star) withObject:self afterDelay:1.5];
            [time invalidate];
        }
       
            NSLog(@" bt1 %d",btn1.tag);
             NSLog(@"bt2  %d",btn2.tag);
             NSLog(@" bt3 %d",btn3.tag);
             NSLog(@" bt4  %d",btn4.tag);
        
    }
    
    if (i1==360)
    {
        i1=i1-360;
        i2=i2-360;
        i3=i3-360;
        i4=i4-360;
    }


}
-(void)star
{
    if (btn1.tag==1)
    {
        ZYXInWenViewController *add=[[ZYXInWenViewController alloc]init];
        [self.navigationController pushViewController:add animated:YES];
        NSLog(@"111111");
    }
    else if (btn2.tag==1)
    {
        ZYTianQiViewController *add=[[ZYTianQiViewController alloc]init];
        [self.navigationController pushViewController:add animated:YES];
    }
    else if (btn3.tag==1)
    {
        ZYSouSuoViewController *add=[[ZYSouSuoViewController alloc]init];
        [self.navigationController pushViewController:add animated:YES];
         NSLog(@"22222222");
    }
    else if (btn4.tag==1)
    {

        ZYChengShiViewController *add=[[ZYChengShiViewController alloc]init];
        [self.navigationController pushViewController:add animated:YES];
         NSLog(@"333333333");
    }

}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
